﻿// <copyright file="ProgramAffector.cs" company="Beuth Hochschule für Technik">
// Design Patterns for C# developed by Steps
// Copyright (C) 2009 Stefan "dersteps@gmail.com" Matyba
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 
// either version 3 of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/.
// </copyright>
// <author>Stefan Matyba</author>
// <email>dersteps@gmail.com</email>
// <date>2009-10-20</date>
// <summary>Breakdown application logic - default implementation of the IProgramAffector interface</summary>

namespace Breakdown.Logic
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Breakdown.Aspects;

    /// <summary>
    /// Represents the part of a firewall rule that affects only a single (or all) program(s)
    /// </summary>
    [Logged]
    public class ProgramAffector : IProgramAffector
    {
        /// <summary>
        /// The full path to the program's executable file
        /// </summary>
        private FileInfo _affectedProgram;

        /// <summary>
        /// If true, this rule affects all executable programs
        /// </summary>
        private bool _affectsAll;

        /// <summary>
        /// Initializes a new instance of the ProgramAffector class. By default, all programs are affected
        /// </summary>
        public ProgramAffector()
        {
            this._affectsAll = true;
        }

        /// <summary>
        /// Gets or sets the executable file of the program affected. Is null if this affector affects all programs.
        /// </summary>
        public FileInfo AffectedProgram
        {
            get { return this._affectedProgram; }
            set { this._affectedProgram = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether or not all programs are affected by this rule
        /// </summary>
        public bool AffectsAllPrograms
        {
            get { return this._affectsAll; }
            set
            {
                this._affectsAll = value;
                this._affectedProgram = value ? null : this._affectedProgram;
            }
        }
    }
}
